package com.demo.controller;


import java.util.List;

import com.demo.annotation.GlobalInterceptor;
import com.demo.entity.dto.SessionWebUserDto;
import com.demo.entity.enums.GroupStatusEnum;
import com.demo.entity.po.GroupInfo;

import com.demo.entity.query.GroupInfoQuery;

import com.demo.entity.vo.PaginationResultVO;

import com.demo.entity.vo.ResponseVO;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.demo.service.GroupInfoService;

/**
 * @Description:小组表Controller
 * @Date:2025-03-01
 * @author：author
*/
@RestController
@RequestMapping("/group")
public class GroupInfoController extends ABaseController {

	@Resource
	private GroupInfoService groupInfoService;


	/**
	 * 查询群组
	 */
	@RequestMapping("/loadDataList")
	@GlobalInterceptor
	public ResponseVO loadDataList(HttpSession session,
								   GroupInfoQuery query) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		PaginationResultVO<GroupInfo> resultVO=null;
		switch (query.getType()) {
			case 0:
				query.setCreatorId(webUserDto.getUserId());
				query.setStatus(GroupStatusEnum.ENABLE.getStatus());
				query.setOrderBy("update_time desc");
				resultVO = groupInfoService.findListByPage(query);
				break;
			case 1:
				query.setCreatorId(webUserDto.getUserId());
				resultVO = groupInfoService.findMyJoinGroup(query);
				break;
		}
		return getSuccessResponseVO(resultVO);
	}
	/**
	 * 新增
	 */
	@RequestMapping("/add")
	@GlobalInterceptor
	public ResponseVO add(HttpSession session,
						  GroupInfo bean) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		bean.setCreatorId(webUserDto.getUserId());
		this.groupInfoService.add(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 新增
	 */
	@RequestMapping("/update")
	@GlobalInterceptor
	public ResponseVO update(HttpSession session,
						  GroupInfo bean) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		bean.setCreatorId(webUserDto.getUserId());
		this.groupInfoService.updateInfo(bean);
		return getSuccessResponseVO(null);
	}


	@RequestMapping("/delete")
	@GlobalInterceptor
	public ResponseVO update(HttpSession session, Long groupId) {
		SessionWebUserDto webUserDto = getUserInfoFromSession(session);
		GroupInfoQuery query = new GroupInfoQuery();
		query.setGroupId(groupId);
		query.setCreatorId(webUserDto.getUserId());
		this.groupInfoService.deleteByParam(query);
		return getSuccessResponseVO(null);
	}

}